// Author  : Morbid
// Time    : 2022/04/30 21:30
// FileName: Main_908.java
// Software: IntelliJ IDEA

public class Main_908 {
    //908. 最小差值 I
    static int smallestRangeI(int[] nums, int k) {
        int[] maxMin = maxMin(nums);
        return Math.max(maxMin[1] - maxMin[0] - k * 2, 0);
    }

    //取最值
    static int[] maxMin(int[] list) {
        int max = list[0], min = list[0];
        for (int i = 1; i < list.length; i++) {
            if (list[i] > max)
                max = list[i];
            if (list[i] < min)
                min = list[i];
        }
        int[] ret = new int[2];
        ret[0] = min;
        ret[1] = max;
        return ret;
    }


    public static void main(String[] args) {
        int[] nums = {0,10};
        int k = 2;
        System.out.println(smallestRangeI(nums, k));
    }

}
